﻿//-----------------------------------------------------------------------
// <copyright file="Designer.cs" company="Microsoft">
//     Copyright (c) AGALTIER, Microsoft. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace ArchiSimple.Windows.Tools
{
    using System;
    using System.Linq;
    #if NETFX_CORE
    using global::Windows.UI.Xaml.Controls;
    using global::Windows.UI.Xaml.Media;
    #else
    using System.Windows.Media;
    #endif
    using System.Collections.Generic;
    using ArchiSimple.Windows.Model;

    /// <summary>
    /// TODO: Provide summary section in the documentation header.
    /// </summary>
    public class Designer
    {
        public PathFigure MakePath(IEnumerable<Point> points)
        {
            var figure = new PathFigure();

            if (points != null)
            {
                figure.StartPoint = points.FirstOrDefault().ToWindowsPoint();

                var polyLine = new PolyLineSegment();

                foreach (var point in points.Skip(1))
                {
                    polyLine.Points.Add(point.ToWindowsPoint());
                }

                figure.Segments.Add(polyLine);
            }

            return figure;
        }

        public void SetPoint(PathFigure figure, int indexPoint, Point value)
        {
            if (figure != null)
            {
                if (indexPoint == 0)
                {
                    figure.StartPoint = value.ToWindowsPoint();
                }
                else
                {
                    var polyLine = figure.Segments[0] as PolyLineSegment;
                    polyLine.Points[indexPoint - 1] = value.ToWindowsPoint();
                }
            }
        }
    }
}
